﻿using System;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace Pay.Core {
	[XmlRoot(Namespace = "http://www.china-xmftz.gov.cn/ceb")]
	public class CEB311Message {
		public CEB311Message() {
			Order = new CEB311Order();
			BaseTransfer = new BaseTransfer();
			Guid = System.Guid.NewGuid().ToString();
			Version = "1.0";
		}
		[XmlAttribute("guid")]
		public string Guid { get; set; }
		[XmlAttribute("version")]
		public string Version { get; set; }
		public CEB311Order Order { get; set; }
		public BaseTransfer BaseTransfer { get; set; }
	}

	public class CEB311Order {
		public CEB311Order() {
			OrderHead = new OrderHead();
			OrderList = new List<OrderList>();
		}
		public OrderHead OrderHead { get; set; }

		[XmlElement("OrderList")]
		public List<OrderList> OrderList { get; set; }
	}

	public class OrderHead {
		public OrderHead() {
			guid = Guid.NewGuid().ToString();
			appType = 1;
			appStatus = 2;
			orderType = "I";
			appTime = DateTime.Now.ToString("yyyyMMddHHmmss");
			ebcCode = "3502160GPV";
			ebcName = "厦门创富互动网络科技有限公司";
			ebpCode = "3502160GPV";
			ebpName = "厦门创富互动网络科技有限公司";
			applyTo = "BOTH";
			tradeMode = "9610";
			currency = "142";
			consigneeIdType = "1";
			payCode = "1108967996";
			payName = "易智付科技（北京）有限公司";
			consignor = "李艮琪";
			consignorTelephone = "0925686999";
			consignorAddress = "台南市东区裕晨路370号";
			consignorCountry = "142";
			tradeCountry = "142";
		}
		/// <summary>
		/// 企业系统生成36位唯一序号（英文字母大写）
		/// </summary>
		public string guid { get; set; }
		/// <summary>
		/// 企业报送类型。1-新增 2-变更 。默认为1
		/// </summary>
		public int appType { get; set; }
		/// <summary>
		/// 企业报送时间。格式:YYYYMMDDhhmmss
		/// </summary>
		public string appTime { get; set; }
		/// <summary>
		/// 业务状态: 固定填写 2-申报
		/// </summary>
		public int appStatus { get; set; }
		/// <summary>
		/// 电子订单类型：I进口
		/// </summary>
		public string orderType { get; set; }
		/// <summary>
		/// 交易平台的订单编号，同一交易平台的订单编号应唯一。订单编号长度不能超过60位
		/// </summary>
		public string orderNo { get; set; }
		/// <summary>
		/// 电商平台的海关注册登记编号；电商平台未在海关注册登记，由电商企业发送订单的，以中国电子口岸发布的电商平台标识编号为准
		/// </summary>
		public string ebpCode { get; set; }
		/// <summary>
		/// 电商平台的海关注册登记名称；电商平台未在海关注册登记，由电商企业发送订单的，以中国电子口岸发布的电商平台名称为准
		/// </summary>
		public string ebpName { get; set; }
		/// <summary>
		/// 电商企业的海关注册登记编号
		/// </summary>
		public string ebcCode { get; set; }
		/// <summary>
		/// 电商企业的海关注册登记名称
		/// </summary>
		public string ebcName { get; set; }
		/// <summary>
		/// 商品实际成交价，含非现金抵扣金额
		/// </summary>
		public decimal goodsValue { get; set; }
		/// <summary>
		/// 不包含在商品价格中的运杂费，无则填写"0"
		/// </summary>
		public decimal freight { get; set; }
		/// <summary>
		/// 使用积分、虚拟货币、代金券等非现金支付金额，无则填写"0"
		/// </summary>
		public decimal discount { get; set; }
		/// <summary>
		/// 企业预先代扣的税款金额，无则填写“0”
		/// </summary>
		public decimal taxTotal { get; set; }
		/// <summary>
		/// 商品价格+运杂费+代扣税款-非现金抵扣金额，与支付凭证的支付金额一致。
		/// </summary>
		public decimal acturalPaid { get; set; }
		/// <summary>
		/// 限定为人民币，填写“142”
		/// </summary>
		public string currency { get; set; }
		/// <summary>
		/// 订购人的交易平台注册号
		/// </summary>
		public string buyerRegNo { get; set; }
		/// <summary>
		/// 订购人的真实姓名
		/// </summary>
		public string buyerName { get; set; }
		/// <summary>
		/// 1-身份证,2-其它。限定为身份证，填写“1”
		/// </summary>
		public string buyerIdType { get; set; }
		/// <summary>
		/// 订购人的身份证件号码
		/// </summary>
		public string buyerIdNumber { get; set; }
		/// <summary>
		/// 支付企业的海关注册登记编号
		/// </summary>
		public string payCode { get; set; }
		/// <summary>
		/// 支付企业在海关注册登记的企业名称
		/// </summary>
		public string payName { get; set; }
		/// <summary>
		/// 支付企业唯一的支付流水号
		/// </summary>
		public string payTransactionId { get; set; }
		/// <summary>
		/// 商品批次号
		/// </summary>
		public string batchNumbers { get; set; }
		/// <summary>
		/// 收货人姓名，必须与电子运单的收货人姓名一致
		/// </summary>
		public string consignee { get; set; }
		/// <summary>
		/// 收货人联系电话，必须与电子运单的收货人电话一致
		/// </summary>
		public string consigneeTelephone { get; set; }
		/// <summary>
		/// 收货地址，必须与电子运单的收货地址一致
		/// </summary>
		public string consigneeAddress { get; set; }
		/// <summary>
		/// 填写参考国家统计局公布的《国家行政区划代码表》
		/// </summary>
		public string consigneeDistrict { get; set; }
		/// <summary>
		/// 备注
		/// </summary>
		public string note { get; set; }
		/// <summary>
		/// 厦门单一窗口为每家企业发放的报文安全传输密钥: xmKjdsKey 
		///xmKjdsKey 和 企业业务数据组合生成传输签,  用于保证企业报文传输安全性
		///订单传输签生成规则:  md5 ( xmKjdsKey + ebcCode + orderNo + appTime ) 
		/// </summary>
		public string applyKey { get; set; }
		/// <summary>
		/// 暂定申报海关国检填 "BOTH", 只申报海关填 "CUS", 只申报国检填 "CIQ" 
		/// </summary>
		public string applyTo { get; set; }
		/// <summary>
		/// 直购进口填写“9610”，保税进口填写“1210”
		/// </summary>
		public string tradeMode { get; set; }
		/// <summary>
		/// 1-身份证,2-其它,3-军官证,4-护照
		/// </summary>
		public string consigneeIdType { get; set; }
		/// <summary>
		/// 收货人证件号码, 必须与清单的收货人证件号码一致
		/// </summary>
		public string consigneeIdNumber { get; set; }
		/// <summary>
		/// 发货人, 必须与电子运单和清单的发货人姓名一致
		/// </summary>
		public string consignor { get; set; }
		/// <summary>
		/// 发货人电话, 必须与电子运单的发货人电话一致
		/// </summary>
		public string consignorTelephone { get; set; }
		/// <summary>
		/// 发货人地址, 必须与电子运单和清单的发货人地址一致
		/// </summary>
		public string consignorAddress { get; set; }
		/// <summary>
		/// 发货人所在国代码, 填写参考《国别代码表》, 必须与电子运单的发货人所在国一致
		/// </summary>
		public string consignorCountry { get; set; }
		/// <summary>
		/// 贸易合作公司的国别代码, 填写参考《国别代码表》
		/// </summary>
		public string tradeCountry { get; set; }
	}

	public class OrderList {
		public OrderList() {
			currency = "142";
		}
		/// <summary>
		/// 从1开始的递增序号
		/// </summary>
		public int gnum { get; set; }
		/// <summary>
		/// 电商企业自定义的商品货号（SKU）
		/// </summary>
		public string itemNo { get; set; }
		/// <summary>
		/// 交易平台销售商品的中文名称
		/// </summary>
		public string itemName { get; set; }
		/// <summary>
		/// 交易平台销售商品的描述信息
		/// </summary>
		public string itemDescribe { get; set; }
		/// <summary>
		/// 国际通用的商品条形码，一般由前缀部分、制造厂商代码、商品代码和校验码组成
		/// </summary>
		public string barCode { get; set; }
		/// <summary>
		/// 填写参考《计量单位代码表》
		/// </summary>
		public string unit { get; set; }
		/// <summary>
		/// 商品实际数量
		/// </summary>
		public decimal qty { get; set; }
		/// <summary>
		/// 商品单价。赠品单价填写为“0”
		/// </summary>
		public decimal price { get; set; }
		/// <summary>
		/// 商品总价，等于单价乘以数量
		/// </summary>
		public decimal totalPrice { get; set; }
		/// <summary>
		/// 限定为人民币，填写“142”
		/// </summary>
		public string currency { get; set; }
		/// <summary>
		/// 填写参考《国别代码表》
		/// </summary>
		public string country { get; set; }
		/// <summary>
		/// 促销活动，商品单价偏离市场价格的，可以在此说明
		/// </summary>
		public string note { get; set; }
		/// <summary>
		/// 企业商品在国检注册备案通过的备案号
		/// </summary>
		public string goodsRegNoCiq { get; set; }
		/// <summary>
		/// 包装种类代码, 填写参考《国检包装种类代码表》
		/// </summary>
		public string wrapTypeCiq { get; set; }
	}

	public class BaseTransfer {
		public BaseTransfer() {
			copCode = "3502160GPV";
			copName = "厦门创富互动网络科技有限公司";
			dxpMode = "DXP";
			dxpId = "DXPENT0000015516";
            note = " ";
		}
		/// <summary>
		/// 报文传输的企业代码
		/// </summary>
		public string copCode { get; set; }
		/// <summary>
		/// 报文传输的企业名称
		/// </summary>
		public string copName { get; set; }
		/// <summary>
		/// 填写 "DXP"
		/// </summary>
		public string dxpMode { get; set; }
		/// <summary>
		/// 向中国电子口岸数据中心申请数据交换平台的用户编号
		/// </summary>
		public string dxpId { get; set; }
		/// <summary>
		/// 备注
		/// </summary>
		public string note { get; set; }
	}
}
